package com.ck.ips.service.impl.sys;

import com.ck.common.model.Dictionary;
import com.ck.core.constant.CacheConstant;
import com.ck.ips.dao.sys.DictionaryMapper;
import com.ck.ips.service.sys.DictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author linqiang
 * @version v1.0
 * @Description 字典
 * @date 2019-05-09 17:53
 */
@Service(value = "dictionaryService")
public class DictionaryServiceImpl implements DictionaryService {

    @Autowired
    private DictionaryMapper dictionaryMapper;

    /**
     * 根据类型查询
     *
     * @param type 类型
     * @return List
     */
    @Override
    @Cacheable(value = CacheConstant.CACHE_NAME_CK_SPRING_CACHE_DICT,key = "#type")
    public List<Dictionary> listByType(String type) {
        return dictionaryMapper.listByType(type);
    }

    /**
     * 根据类型和值判断是否存在
     *
     * @param type  类型
     * @param value 值
     * @return true存在，false不存在
     */
    @Override
    public boolean isExists(String type, String value) {
        return dictionaryMapper.count(type, value) > 0;
    }


}
